home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / For MPW Users / UserStartup•VU
Encoding:
Text File  |  1998-06-04  |  9.7 KB  |  270 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        UserStartup•VU
  3. #
  4. #    Contains:    Initializations for Virtual User extension in MPW
  5. #
  6. #     How to use:    Drop this file in your MPW Folder and then launch MPW, or, 
  7. #                open it, select all and hit enter if MPW is already running.
  8. #
  9. #    Written by:    Stuart Russell from original UserStartup•VU by P Nagarajan
  10. #
  11. #    Copyright:    © 1990-1994 by Apple Computer, Inc., all rights reserved.
  12. #
  13. #    Change History:
  14. #
  15. #        02/22/90       naga         creation 
  16. #        02/07/94       SBR         changed to use a Prefs file 
  17. #        05/17/94       SBR         fixed for multiple prefs items 
  18. #        05/28/94       SBR         opens prefs file as target for speed 
  19. #
  20. #    Sets the location of any folders needed for a module. A module is 
  21. #    defined as a folder containing things you want to use while in MPW. 
  22. #     If the folder can't be found, automatically prompts the user for it and 
  23. #    creates (or changes) a Prefs file to remember where the folder was found.
  24. #    If you want to do any other type of setup, like inserting menu items
  25. #    or validating server folders, you are on your own!
  26.  
  27. #    In general, things which need customization are either next to or surrounded 
  28. #    by commented lines beginning with #####.
  29.  
  30. #    To modify this startup script to work with a new module:
  31. #        1)    Change customPrefsDir (below) to the name of the preferences folder  
  32. #            for this module. Be sure to terminate it with a colon. It can be an  
  33. #            existing folder name.
  34. #        
  35. #            for example:
  36. #                set customPrefsDir "My Prefs Folder:"
  37. #        
  38. #        2)    Change customPrefsFile (below) to the name of the preferences file  
  39. #            for this module. Do not terminate it with a colon. It can be an  
  40. #            existing file name.
  41. #        
  42. #            for example:
  43. #                set customPrefsFile "My Prefs File"
  44. #        
  45. #        3)    Decide how many prefs items you want and what to name them.
  46. #            Modify, add or delete items as described below.
  47. #    
  48. #        4)    Locate the lines surrounded by
  49. #                "##### begin custom statements for this module"
  50. #                "##### end custom statements for this module"
  51. #            Modify, delete, or add lines in this section however you want.
  52. #            They will not execute unless all prefs items are valid.
  53. #    
  54. #        5)    Modify the comments beginning with "File:" and "Contains" at the
  55. #            beginning of this file to reflect the new module.
  56. #    
  57. #    To modify a preference item:
  58. #        1)    Locate the line below which says 
  59. #                "##### preference items set by this script:".
  60. #            
  61. #        2)    Just below that, locate the name of the prefs item you want to modify.
  62. #        
  63. #        3)    Replace all occurrences of that name in this file with the new name. 
  64. #        
  65. #        4)    Locate the section below surrounded by 
  66. #                ##### begin validation for this prefs item
  67. #                ##### end validation for this prefs item.
  68. #                
  69. #        5)    The first line should be the actual validation of that prefs item. 
  70. #            We look for a key file name inside the folder for the module. You 
  71. #            need to modify the key file name to make it unique.
  72. #                
  73. #            for example:
  74. #            
  75. #                The original validation line might look like:
  76. #                    if `Exists -f "{VUDir}"Startup` != ""
  77. #                where VUDir is the old name of this prefs item, and Startup is 
  78. #                the key file.
  79. #            
  80. #                So you change it to 
  81. #                    if `Exists -f "{newItem}"myPrefKeyFile` != ""
  82. #                where newItem is the new name of this item as modified in 3),
  83. #                and myPrefKeyFile is the string name of the key file inside the 
  84. #                project folder.
  85. #    
  86. #        6)    In the "else" clause of the validation section, just below the beep,
  87. #            you can see the directory locator command, used in case the prefs
  88. #            item was not valid or the directory was not found. You need to modify 
  89. #            the prompting text to tell the user which directory to find.
  90. #                
  91. #            for example:
  92. #            
  93. #                The original directory locator command line might look like:
  94. #                    (Set VUDir `getfilename -d -m 'Find old folder'`) ∑ dev:null
  95. #                where VUDir is the old name of this prefs item, and 
  96. #                'Find the Virtual User folder' is the old prompting text for the
  97. #                user to locate the directory.
  98. #            
  99. #                So you change it to 
  100. #                    (Set newItem `getfilename -d -m 'Find new folder'`) ∑ dev:null
  101. #                where newItem is the new name of this prefs item as modified 
  102. #                in 3), and 'Find new folder' is the new prompting text.
  103. #                
  104. #        7)    Locate the lines surrounded by
  105. #                "##### begin custom statements for this module"
  106. #                "##### end custom statements for this module"
  107. #            Modify, delete, or add lines in this section however you want.
  108. #            They will not execute unless all prefs items are valid.
  109. #    
  110. #    To add a new preference item:
  111. #        1)    Locate the line below which says 
  112. #                "##### preference items set by this script:"
  113. #            
  114. #        2)    Duplicate the first line below that, which should be the name of an 
  115. #            existing prefs item.
  116. #        
  117. #        3)    Replace the duplicated prefs item name with your new name.
  118. #            Do not replace all!
  119. #    
  120. #        4)    Select the last section of this file surrounded by
  121. #                "##### begin find or create this prefs item"
  122. #                "##### end find or create this prefs item",
  123. #            including the surrounding comments.
  124. #            
  125. #        5)    Select Copy from the Edit menu, type the right arrow key, then type 
  126. #            Return. The return inserts a blank line to keep the script readable.
  127. #        
  128. #        6)    Select Paste from the Edit menu.
  129. #            
  130. #        7)    Select the last section of this file surrounded by
  131. #                "##### begin validation for this prefs item"
  132. #                "##### end validation for this prefs item",
  133. #            including the surrounding comments.
  134. #            
  135. #        8)    Select Copy from the Edit menu, type the right arrow key, then type 
  136. #            Return. The return inserts a blank line to keep the script readable.
  137. #        
  138. #        9)    Select Paste from the Edit menu.
  139. #            
  140. #        10)    Replace the old prefs item name with the new name you used in 3), but
  141. #            only in the two sections you just duplicated. Do not replace all!
  142. #        
  143. #        11)    Replace the validation command line and the find directory command 
  144. #            line as described in 5) and 6) of the "To modify a preference item:"
  145. #            section above.
  146. #    
  147. #        12)    Locate the lines surrounded by
  148. #                "##### begin custom statements for this module"
  149. #                "##### end custom statements for this module"
  150. #            Modify, delete, or add lines in this section however you want.
  151. #            They will not execute unless all prefs items are valid.
  152. #    
  153. #    To delete a preference item:
  154. #        1)    Locate the line below which says 
  155. #                "##### preference items set by this script:".
  156. #            
  157. #        2)    Just below that, locate the name of the prefs item you want to modify,
  158. #            and delete that line.
  159. #        
  160. #        4)    Delete the section of this file surrounded by
  161. #                "##### begin find or create this prefs item"
  162. #                "##### end find or create this prefs item"
  163. #            which contains the prefs item you are trying to delete,
  164. #            including its surrounding comments.
  165. #            
  166. #        5)    Delete the section of this file surrounded by
  167. #                "##### begin validation for this prefs item"
  168. #                "##### end validation for this prefs item"
  169. #            which contains the prefs item you are trying to delete,
  170. #            including the surrounding comments.
  171. #            
  172. #        6)    Delete any lines in the section in this file surrounded by
  173. #                "##### begin custom statements for this module"
  174. #                "##### end custom statements for this module"
  175. #            which refer to the prefs item you are trying to delete.
  176. #        
  177. #        7)    Locate the lines surrounded by
  178. #                "##### begin custom statements for this module"
  179. #                "##### end custom statements for this module"
  180. #            Modify, delete, or add lines in this section however you want.
  181. #            They will not execute unless all prefs items are valid.
  182.         
  183. ##### preference items set by this script:
  184. #    VUDir
  185. #    (Use one line for each item name)
  186. #####
  187.  
  188. set saveExit "{exit}"                            # restored at the end
  189. set exit 0
  190.  
  191. ##### custom name of the prefs folder
  192. set customPrefsDir "Virtual User Stuff:"
  193.  
  194. ##### custom name of the prefs file
  195. set customPrefsFile "VU Preferences"
  196.  
  197. set thePrefsDir "{systemfolder}Preferences:{customPrefsDir}"
  198. if (`exists -d "{thePrefsDir}"` == "")
  199.     newFolder "{thePrefsDir}"                    # create prefs folder if needed
  200. end
  201.  
  202. set thePrefsFile "{thePrefsDir}{customPrefsFile}"
  203. if (`exists -f "{thePrefsFile}"` == "")
  204.     new "{thePrefsFile}"                        # create preferences file and
  205.     target "{thePrefsFile}"                        # send it behind for speed, or
  206. else
  207.     open -t "{thePrefsFile}"                    # open prefs file as target
  208. end
  209.  
  210. sizeWindow 400 200 "{thePrefsFile}"
  211.  
  212. ##### begin find or create this prefs item
  213. ##### duplicate this section for each prefs item
  214. find • "{thePrefsFile}"                                        
  215. find /set VUDir/ "{thePrefsFile}"
  216. if "{status}" == "2"                            # item is not in prefs file yet
  217.     set VUDir "This is a fake directory:"
  218.     echo "Set VUDir    ∂"{VUDir}∂"∂n" >> "{thePrefsFile}"
  219. end
  220. ##### end find or create this prefs item
  221.  
  222.  
  223. save "{thePrefsFile}"
  224. execute "{thePrefsFile}"                        # set all the preferences here
  225.  
  226. Set exitValue 'OK'
  227. ##### begin validation for this prefs item
  228. ##### duplicate this section for each prefs item
  229. Set EverLooked 0
  230. Loop
  231.     Break if "{exitValue}" == 'cancelled'
  232.     if `Exists -f "{VUDir}Startup"` != ""
  233.         if {EverLooked} == 1                    # If valid, and it changed,
  234.             find • "{thePrefsFile}"                # then update the prefs file
  235.             find /'Set VUDir'[ ∂t]+/Δ:Δ/∂n/ "{thePrefsFile}"
  236.             
  237.             # we cat because path may contain characters significant to: Replace
  238.             echo -n ∂""{VUDir}"∂" | Catenate > "{thePrefsFile}".§
  239.             save "{thePrefsFile}"
  240.             execute "{thePrefsFile}"            # set modified preferences here
  241.         end                                     # if it changed
  242.         
  243.         Break
  244.     else
  245.         Set EverLooked 1                        # If prefs not valid, then user
  246.         Set VUDir ""                # must find the valid folder(s).
  247.     #    Beep
  248.         (Set VUDir `getfilename -d -m 'Find the Virtual User folder'`) ∑ dev:null
  249.         if "{VUDir}" == ""
  250.             set exitValue 'cancelled'
  251.             Break
  252.         end
  253.     end
  254. end
  255. ##### end validation for this prefs item
  256.  
  257.  
  258. if "{exitValue}" == 'OK'
  259.     ##### begin custom statements for this module
  260.     export "{VUDir}"
  261.     Execute "{VUDir}"Startup
  262.     ##### end custom statements for this module
  263. end
  264.  
  265. close "{thePrefsFile}"                    # clean up
  266. set exit "{saveExit}"
  267.  
  268. exit 0 if "{exitValue}" == 'cancelled'    # Allow MPW to continue even
  269. exit 0 if "{exitValue}" == 'OK'            # if this one was cancelled.
  270.